import { MPaginationRes, MPaginationReq } from "@/modules/common"
import { MFunction, EFunctionType, MRole } from "../entities";
import http from '@/utils/request'



let DBList: Array<MFunction> = [];
class PermissionServiceTemp {
    getRoleList(pagination: MPaginationReq): Promise<MPaginationRes> {
        return http.post('/yxd/oa/role/page', pagination).then((res: any) => {
            res as MPaginationRes;
            return Promise.resolve({
                dataList: res.data,
                total: res.total
            })
        })
    }
    deleteRoleItem(id: string) {
        return http.get(`/yxd/oa/role/delete`, { params: { id } })
    }
    editRoleItem(form: MRole) {
        delete form.menuList
        return http.post(`/yxd/oa/role/${form.id ? 'update' : 'add'}`, form)
    }

    getFunctionTree() {
        return http.get('/yxd/oa/menu/tree').then(res => {
            return Promise.resolve(res)
        })
    }
    deleteFunctionItem(id: number) {
        return http.get(`/yxd/oa/menu/delete`, { params: { id } })
    }
    editFunctionItem(form: MFunction) {
        return http.post(`/yxd/oa/menu/${form.id ? 'update' : 'add'}`, form)
    }
}
const PermissionService = new PermissionServiceTemp();
export { PermissionService }